Skip to main content

Include or Replace Work Allocation

Overview

The functions assignWorkItem and assignWorkItem​ById are advanced tools that allow including or replacing assignees in any existing user task, including intermediate events.


Syntax

assignWorkItem

Me.Case.assignWorkItem(string sTaskName, int iNewUserId, bool bReplace)

assignWorkItemById

Me.Case.assignWorkItemById(int iWorkItemId, int iNewUserId, bool bReplace)


Parameters

  • sTaskName: The unique name of the task to which the new user will be added or replaced in assignment.
  • iWorkItemId: The identification number of the work item of the task in which the new user will be added or replaced.
  • iNewUserId: The identification number of the user to be added or replaced.
  • bReplace: A Boolean attribute that determines whether the current allocation will be replaced or updated:
    • true: Replaces all assigned users.
    • false: Adds the user to the assigned users.

Notes

  • It is good practice to save allocated users in a collection if the event is recurring (e.g., when clicking "next" recreates it). Then, the allocation rule will use users from the collection.
  • In sub-processes, the allocation rules only apply to the process being executed. If two tasks share the same name in the parent and child process, the allocation rule applies only to the active process.
  • To retrieve assignees of a task after using the assignWorkItem function in the same event (On Enter, On Save, On Exit), use the method:
    Me.Case.getWorkItem(sTaskName).Assignees
    Avoid using Me.Assignees.

Example: Personal Loan Request Process

In a Personal Loan Request process, a new performer for the Decline Request event is added based on the process phase.


Assignment Rules

PhasePerformer(s) of Event
Applicants PrefilterCase creator
Register Request InformationCase creator, Case creator's Boss
Verify InformationCase creator, Case creator's Boss, Security Leader
Analysis ResultSecurity Leader
DeliveryLoans Vice-president

Activities Selected

  1. On Enter:

    • Verify Applicants Information Task (First activity of Register Request Information phase).
    • Verify Documentation and Information Sub-Process (First activity of Verify Information phase).
  2. On Exit:

    • Exception Request? Gateway (Last activity of Verify Information phase).
    • Verify Collaterals and Products Task (Last activity of Analysis Result phase).

Procedure

  1. Set Performer for the Event:
    Use Step 5 of the Process Wizard.

  2. Create an Expression:
    Add it to the first activity where allocation will be modified.
    Example: Verify Applicants Information Task with the expression executed On Enter.
    ReplaceAllocation_01

  3. Save Expression:
    Apply the expression to all defined activities. Save the process and test it.

// Get the Display name of the current activity
var actDisplayName = Me.Task.DisplayName;
// Load in a variable the Event id
var eventName = Me.Task.Name;
// For both positions vice-president and leader, we assume

// that there is only one user for each one

var oUser = CHelper.getUsersForPosition("LoansVicepresident");

var loansVpId = oUser[0];

oUser = CHelper.getUsersForPosition("SecurityLeader");

var secLeader = oUser[0];

// Compare the display name with the activities where the

// allocation will change
if (actDisplayName == "Verify Applicants Information")
{
Me.Case.assignWorkItem(eventName, Me.Case.Creator.BossId, false);
}
else if (actDisplayName == "Verify Documentation and Information")
{
Me.Case.assignWorkItem(eventName, secLeader, false);
}
else if (actDisplayName == "Exception Request?")
{
// The allocation will be replaced
Me.Case.assignWorkItem(eventName, secLeader, true);
}
else if (actDisplayName == "Verify Collaterals and Products")
{
Me.Case.assignWorkItem(eventName, loansVpId, true);
}
  1. Result:
    Allocation will dynamically change based on the rules defined for each activity.
    ReplaceAllocation_02
If you prefer to use assignWorkItem​ById function, the code will be:



// Get the Display name of the current activity
var actDisplayName = Me.Task.DisplayName;
// Load in a variable the workitem id

var workItem = Me.Id;
// For both positions vice-president and leader, we assume

// that there is only one user for each one

var oUser = CHelper.getUsersForPosition("LoansVicepresident");

var loansVpId = oUser[0];

oUser = CHelper.getUsersForPosition("SecurityLeader");

var secLeader = oUser[0];
// Compare the display name with the activities where the
// allocation will change
if (actDisplayName == "Verify Applicants Information")
{
Me.Case.assignWorkItem​ById(workItem, Me.Case.Creator.BossId, false);
}
else if (actDisplayName == "Verify Documentation and Information")
{
Me.Case.assignWorkItem​ById(workItem, secLeader, false);
}
else if (actDisplayName == "Exception Request?")
{
// The allocation will be replaced
Me.Case.assignWorkItem​ById(workItem, secLeader, true);
}
else if (actDisplayName == "Verify Collaterals and Products")
{
Me.Case.assignWorkItem​ById(workItem, loansVpId, true);
}



Save the expression and continue.


Add the expression created above in the corresponding event of the other activities previously defined. Once you have set the expression in all the activities, save your process and run it for testing.